package com.fengke.dao.model;

import java.math.BigDecimal;
import java.util.Date;

import org.apache.commons.lang3.builder.ToStringBuilder;

public class PaymentModel extends BaseEntity {
	private static final long serialVersionUID = -2903271819968489897L;
	/**
	 * 类型
	 */
	public enum Type {
		/** 订单支付 */
		payment(0),
		/** 预存款充值 */
		recharge(1),
		/** 手机号充值 */
		phoneCharge(2);
		
		private int type;

		Type(int type) {
			this.type = type;
		}

		public int getType() {
			return type;
		}
	}
	/**
	 * 方式
	 */
	public enum Method {
		/** 在线支付 */
		online(0),
		/** 线下支付 */
		offline(1),
		/** 预存款支付 */
		deposit(2);
		private int method;
		Method(int method) {
			this.method = method;
		}
		public int getMethod() {
			return method;
		}
	}
	/**
	 * 状态
	 */
	public enum Status {
		/** 等待支付 */
		wait(0),
		/** 支付成功 */
		success(1),
		/** 支付失败 */
		failure(2);
		private int status;
		Status(int status) {
			this.status = status;
		}
		public int getStatus() {
			return this.status;
		}
	}
	/** 收款账号 */
	private String account;
	/** 付款金额 */
	private BigDecimal amount;
	/** 收款银行 */
	private String bank;
	/** 到期时间 */
	private Date expire;
	/** 支付手续费 */
	private BigDecimal fee;
	/** 备注 */
	private String memo;
	/** 方式 */
	private Method method;
	private Integer mmethod;
	/** 操作员 */
	private String operator;
	/** 付款人 */
	private String payer;
	/** 付款日期 */
	private Date paymentDate;
	/** 支付方式 */
	private String paymentMethod;
	/** 支付插件ID */
	private String paymentPluginId;
	/** 编号 */
	private String sn;
	/** 状态 */
	private Status status;
	private Integer mstatus;
	/** 类型 */
	private Type type;
	private Integer mtype;
	/** 会员 */
	private MemberModel member;
	/** 订单 */
	private OrderModel order;
	/**
	 * 主题
	 */
	private String subject;
	/** 商户id */
    private AdminModel adminModel;
    @Override
    public String toString() {
    	return ToStringBuilder.reflectionToString(this);
    }
	public String getAccount() {
		return account;
	}
	public void setAccount(String account) {
		this.account = account;
	}
	public BigDecimal getAmount() {
		return amount;
	}
	public void setAmount(BigDecimal amount) {
		this.amount = amount;
	}
	public String getBank() {
		return bank;
	}
	public void setBank(String bank) {
		this.bank = bank;
	}
	public Date getExpire() {
		return expire;
	}
	public void setExpire(Date expire) {
		this.expire = expire;
	}
	public BigDecimal getFee() {
		return fee;
	}
	public void setFee(BigDecimal fee) {
		this.fee = fee;
	}
	public String getMemo() {
		return memo;
	}
	public void setMemo(String memo) {
		this.memo = memo;
	}
	public Method getMethod() {
		return method;
	}
	public void setMethod(Method method) {
		this.method = method;
	}
	public Integer getMmethod() {
		if(this.method == null) {
			return null;
		}
		this.mmethod = this.method.getMethod();
		return mmethod;
	}
	public void setMmethod(Integer mmethod) {
		if(mmethod == null) {
			return;
		}
		if(mmethod == Method.online.getMethod()) {
			this.method = Method.online;
		} else if(mmethod == Method.offline.getMethod()) {
			this.method = Method.offline;
		} else if(mmethod == Method.deposit.getMethod()) {
			this.method = Method.deposit;
		}
		this.mmethod = this.method.getMethod();
	}
	public String getOperator() {
		return operator;
	}
	public void setOperator(String operator) {
		this.operator = operator;
	}
	public String getPayer() {
		return payer;
	}
	public void setPayer(String payer) {
		this.payer = payer;
	}
	public Date getPaymentDate() {
		return paymentDate;
	}
	public void setPaymentDate(Date paymentDate) {
		this.paymentDate = paymentDate;
	}
	public String getPaymentMethod() {
		return paymentMethod;
	}
	public void setPaymentMethod(String paymentMethod) {
		this.paymentMethod = paymentMethod;
	}
	public String getPaymentPluginId() {
		return paymentPluginId;
	}
	public void setPaymentPluginId(String paymentPluginId) {
		this.paymentPluginId = paymentPluginId;
	}
	public String getSn() {
		return sn;
	}
	public void setSn(String sn) {
		this.sn = sn;
	}
	public Status getStatus() {
		return status;
	}
	public void setStatus(Status status) {
		this.status = status;
	}
	public Integer getMstatus() {
		if(this.status == null) {
			return null;
		}
		this.mstatus = this.status.getStatus();
		return mstatus;
	}
	public void setMstatus(Integer mstatus) {
		if(mstatus == null) {
			return;
		}
		if(mstatus == Status.success.getStatus()) {
			this.status = Status.success;
		} else if(mstatus == Status.failure.getStatus()) {
			this.status = Status.failure;
		} else if(mstatus == Status.wait.getStatus()) {
			this.status = Status.wait;
		}
		this.mstatus = this.status.getStatus();
	}
	public Type getType() {
		return type;
	}
	public void setType(Type type) {
		this.type = type;
	}
	public Integer getMtype() {
		if(this.type == null) {
			return null;
		}
		this.mtype = this.type.getType();
		return this.mtype;
	}
	public void setMtype(Integer mtype) {
		if(mtype == null) {
			return;
		}
		if(mtype == Type.payment.getType()) {
			this.type = Type.payment;
		} else if(mtype == Type.recharge.getType()) {
			this.type = Type.recharge;
		} else if(mtype == Type.phoneCharge.getType()) {
			this.type = Type.phoneCharge;
		}
		this.mtype = this.type.getType();
	}
	public MemberModel getMember() {
		return member;
	}
	public void setMember(MemberModel member) {
		this.member = member;
	}
	public OrderModel getOrder() {
		return order;
	}
	public void setOrder(OrderModel order) {
		this.order = order;
	}
	public String getSubject() {
		return subject;
	}
	public void setSubject(String subject) {
		this.subject = subject;
	}
	public AdminModel getAdminModel() {
		return adminModel;
	}
	public void setAdminModel(AdminModel adminModel) {
		this.adminModel = adminModel;
	}
	/**
	 * 获取有效金额
	 * 
	 * @return 有效金额
	 */
	public BigDecimal getEffectiveAmount() {
		BigDecimal effectiveAmount = getAmount().subtract(getFee());
		return effectiveAmount.compareTo(new BigDecimal(0)) > 0 ? effectiveAmount : new BigDecimal(0);
	}

	/**
	 * 判断是否已过期
	 * 
	 * @return 是否已过期
	 */
	public boolean hasExpired() {
		return getExpire() != null && new Date().after(getExpire());
	}
}
